package com.turnengine.client.global.error.command.set;

import static com.javabi.common.dependency.DependencyFactory.getDependency;

import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.errorcode.ErrorCodeException;
import com.javabi.command.executor.ICommandExecutorService;
import com.turnengine.client.global.error.command.GetCommandStackTrace;
import com.turnengine.client.global.error.command.GetCommandStackTraceList;
import com.turnengine.client.global.error.command.IGetCommandStackTrace;
import com.turnengine.client.global.error.command.IGetCommandStackTraceList;
import com.turnengine.client.local.error.bean.ILocalTrace;
import java.util.List;

/**
 * The Global Error Command Set.
 */
public class GlobalErrorCommandSet implements IGlobalErrorCommandSet {

	@Override
	public ILocalTrace getCommandStackTrace(long loginId, long id) {
		IGetCommandStackTrace command = new GetCommandStackTrace(loginId, id);
		ICommandExecutorService service = getDependency(ICommandExecutorService.class);
		IExecutableCommandResponse<ILocalTrace> response = service.execute(command);
		if (response.hasErrors()) {
			throw new ErrorCodeException(response);
		}
		return response.getReturnValue();
	}

	@Override
	public List<ILocalTrace> getCommandStackTraceList(long loginId, long from, long to) {
		IGetCommandStackTraceList command = new GetCommandStackTraceList(loginId, from, to);
		ICommandExecutorService service = getDependency(ICommandExecutorService.class);
		IExecutableCommandResponse<List<ILocalTrace>> response = service.execute(command);
		if (response.hasErrors()) {
			throw new ErrorCodeException(response);
		}
		return response.getReturnValue();
	}
}
